//
//  PKProductsTableViewCell.m
//  PianKe
//
//  Created by lanou on 15/12/22.
//  Copyright © 2015年 KFC. All rights reserved.
//

#import "PKProductsTableViewCell.h"
#import <UIImageView+WebCache.h>
@implementation PKProductsTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self addSubViews];
        
    }
    
    return self;
    
    
}

// 铺设cell
- (void)addSubViews
{
    
    self.myImageV = [[UIImageView alloc] initWithFrame:CGRectMake(20, 10, kScreenWidth - 40, (kScreenWidth - 40) * 300 / 608)];
   // self.myImageV.backgroundColor = [UIColor greenColor];
    [self.contentView addSubview:self.myImageV];
    
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.myImageV.left, self.myImageV.bottom + 5, self.myImageV.width * 2 / 3, 30)];
   // self.titleLabel.backgroundColor = [UIColor orangeColor];
    [self.contentView  addSubview:self.titleLabel];
    
    self.buyButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    self.buyButton.frame = CGRectMake(self.titleLabel.right + 10, self.titleLabel.top,self.myImageV.width * 1 / 3 - 10, self.titleLabel.height);
    self.buyButton.layer.cornerRadius = 15;
    self.buyButton.backgroundColor = [UIColor greenColor];
    [self.buyButton setTitle:@"立即购买" forState:(UIControlStateNormal)];
    [self.contentView addSubview:self.buyButton];
    
    
    
}


// 重写setModel方法
- (void)setProductModel:(PKProductModel *)productModel
{
    _productModel = productModel;
    
    // 赋值
    _titleLabel.text = productModel.title;
   
    // 同步的方式展示,会用SD代替
//    NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:productModel.coverimg]];
//    self.myImageV.image = [UIImage imageWithData:data];
    
    [self.myImageV sd_setImageWithURL:[NSURL URLWithString:productModel.coverimg] placeholderImage:nil];
    
    
    
    
}












- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
